import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from "@angular/common/http";

import { Observable } from "rxjs"

@Injectable({
    providedIn: 'root'
})
export class DictionaryManageService {

    private baseUrl: string = "/api/dict"
    private detailUrl: string = "/api/dictDetail"
    private detailAllUrl: string = '/api/dictDetail/getDictDetailsAll'

    public detailParantName: string = "";
    public detailParentId: number = -1;

    constructor(
        private http: HttpClient
    ) { }

    /* 列表服务 */
    getList(data): Observable<any> {
        let _dataJson = {
            params: {
                ...data,
                page: data.page - 1
            }
        }
        return this.http.get(this.baseUrl, _dataJson).pipe()
    }

    listAdd(data): Observable<any> {
        let _dataJson = {
            ...data
        }
        return this.http.post(this.baseUrl, _dataJson).pipe()
    }

    listDelete(id): Observable<any> {
        return this.http.delete(`${this.baseUrl}/${id}`).pipe();
    }

    listEdit(data): Observable<any> {
        let _dataJson = data
        return this.http.put(this.baseUrl, _dataJson).pipe();
    }

    /* 详情服务 */
    getDetail(data): Observable<any> {
        let _dataJson = {
            params: {
                ...data,
                page: data.page - 1
            }
        }
        return this.http.get(this.detailUrl, _dataJson).pipe();
    }
    detailAdd(data): Observable<any> {
        let _dataJson = {
            ...data
        }
        return this.http.post(this.detailUrl, _dataJson).pipe();
    }
    apiDelete(id): Observable<any> {
        return this.http.delete(`${this.detailUrl}/${id}`).pipe();
    }
    apiEdit(data): Observable<any> {
        let _dataJson = {
            ...data
        }
        return this.http.put(this.detailUrl, _dataJson).pipe();
    }
    // 获取字典详情  全部不分页 (张晓红) (审批管理)
    getDetailAll(data): Observable<any> {
        let _dataJson = {
            params: {
                ...data
            }
        }
        return this.http.get(this.detailAllUrl, _dataJson);
    }

}
